<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<c:set var="path" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>${block.name } - 校园论坛 - 相思湖学院</title>
<link rel="shortcut icon" href="static/image/logo_little.png">
<link rel="stylesheet" type="text/css" href="static/css/bootstrap.css" >
<link rel="stylesheet" type="text/css" href="static/css/top.css" >
<link rel="stylesheet" type="text/css" href="static/css/page.css" >
<link rel="stylesheet" type="text/css" href="static/css/block.css" >
</head>
<body>
	<div class="top">
		<img class="logo" alt="相思湖学院论坛" src="static/image/logo.png">
		<form action="search" method="post" onsubmit="return isEmpty()">
			<input  id="search" name="search" type="text" value="" placeholder="请输入搜索内容">
		    <button type="submit" class="submit">搜索</button>
		</form>
		<script type="text/javascript">
			function isEmpty() {
				if(document.getElementById("search").value == "") {
					$('<div>').appendTo('body').addClass('alert alert-info').html("请输入搜索内容").show().delay(1500).fadeOut();
					return false;
				}
				return true;
			}
		</script>
		<c:if test="${user != null }">
			<div class="user">
				<span><a style="font-weight: 800;color: black;" href="userinfo">${user.username }</a></span>
				<span>|</span>
				<div class="dropdown" style="display: inline-block;">
					<a data-toggle="dropdown" class="dropdown-toggle" href="#">我的<strong class="caret"></strong></a>
					<ul class="dropdown-menu">
						<li><a href="user?id=${user.id }&selected=mytopic">帖子</a></li>
						<!-- <li><a href="#">收藏</a></li>
						<li><a href="#">好友</a></li> -->
					</ul>
				</div>
				<span>|</span>
				<span><a href="userinfo">设置</a></span>
				<!-- <span>|</span>
				<span><a href="#">消息</a></span> -->
				<span>|</span>
				<div class="dropdown" style="display: inline-block;">
					<a data-toggle="dropdown" class="dropdown-toggle" href="#">提醒<strong class="caret"></strong></a>
					<ul class="dropdown-menu">
						<li><a href="notice">消息</a></li>
						<!-- <li><a href="#">新听众</a></li> -->
					</ul>
				</div>
				<span>|</span>
				<span><a href="exit">退出</a></span>
				<c:if test="${user.avatar != null && user.avatar != '' }">
					<img class="avatar" src="${user.avatar }">
				</c:if>
				<c:if test="${user.avatar == null || user.avatar == '' }">
					<img class="avatar" src="static/image/noavatar.jpg">
				</c:if>
			</div>
		</c:if>
		<c:if test="${user == null }">
			<div class="visitor">
				<a href="ps.login">登陆</a>
				<a href="${path }/register.jsp">注册</a>
			</div>
		</c:if>
	</div>
	<div class="contral">
		<div class="title">
			<a href="forum" class="nvhm" title="首页"></a>
			<em></em>
			<a href="forum">论坛</a>
			<em></em>
			<a>${partition.name }</a>
			<em></em>
			<a href="#">${block.name }</a>
		</div>
		<div class="head">
			<div style="height: 35px;">
				<h2>
					${block.name }
				</h2>
			</div>
		</div>
		<div class="mn">
			<div class="pg">
				<a href="ps.createTopic?bid=${block.id }&operation=createTopic"><button title="发新帖">发 帖</button></a>
				<div class="pagination">
					<c:if test="${page.hasPreviousPage == true }">
						<a href="block?bid=${block.id }&orderBy=${orderBy }&pageNum=${page.prePage}">上一页</a>
					</c:if>
					<c:if test="${page.pageNum > 3 }">
						<a href="block?bid=${block.id }&orderBy=${orderBy }&pageNum=1">1 ...</a>
					</c:if>
					<c:set var="index" value="${page.pageNum - (page.pageNum == page.pages ? 4:(page.pageNum == (page.pages - 1) ? 3:2))}" />
					<c:forEach var="x" begin="1" end="${page.pageNum == page.pages ? 4:(page.pageNum == (page.pages - 1)) ? 3:2 }" step="1"> 
						<c:if test="${index > 0 && index < page.pageNum }">
							<a href="block?bid=${block.id }&orderBy=${orderBy }&pageNum=${index}">${index }</a>
						</c:if>
						<c:set var="index" value="${index + 1}" />
					</c:forEach>
					<c:if test="${page.pages != 0 }"><strong>${page.pageNum }</strong></c:if>
					<c:set var="index" value="${page.pageNum }" />
					<c:forEach var="x" begin="1" end="${page.pageNum == 1 ? 4:(page.pageNum == 2) ? 3:2 }" varStatus="status" step="1"> 
						<c:set var="index" value="${index + 1}" />
						<c:if test="${index <= page.pages }">
							<a href="block?bid=${block.id }&orderBy=${orderBy }&pageNum=${index}">${index }</a>
						</c:if>
					</c:forEach>
					<c:if test="${page.pageNum < (page.pages - 2) }">
						<a href="block?bid=${block.id }&orderBy=${orderBy }&pageNum=${page.pages}">... ${page.pages }</a>
					</c:if>
					<c:if test="${page.pages != 0 }">
						<label>
							<input type="text" title="输入页码，按回车快速跳转" value="${page.pageNum }"
								onkeydown="if(event.keyCode==13) {window.location='block?bid=${block.id }&orderBy=${orderBy }&pageNum='+this.value;}">
							<span>/${page.pages }页</span>
						</label>
					</c:if>
					<c:if test="${page.hasNextPage == true }">
						<a href="block?bid=${block.id }&orderBy=${orderBy }&pageNum=${page.nextPage }">下一页</a>
					</c:if>
				</div>
			</div>
			<div class="blocks">
				<div class="b_title">
					<div style="width: 70.5%;">
						<span style="border-right: 1px solid #CDCDCD; padding-right: 5px;">全部主题</span>
						<span>
							<c:if test="${orderBy == 'updatetime' }">
								最新
							</c:if>
							<c:if test="${orderBy != 'updatetime' }">
								<a href="block?bid=${block.id }&orderBy=updatetime">最新</a>
							</c:if>
						</span>
						<span>
							<c:if test="${orderBy == 'lastreply' }">
								热门
							</c:if>
							<c:if test="${orderBy != 'lastreply' }">
								<a href="block?bid=${block.id }">热门</a>
							</c:if>
						</span>
						<span>
							<c:if test="${orderBy == 'replies' }">
								热帖
							</c:if>
							<c:if test="${orderBy != 'replies' }">
								<a href="block?bid=${block.id }&orderBy=replies">热帖</a>
							</c:if>
						</span>
						<!-- <span>
							<a href="">精华</a>
						</span>
						<span class="dropdown" style="">
							<a data-toggle="dropdown" class="dropdown-toggle" href="#">更多<strong class="caret"></strong></a>
							<ul class="dropdown-menu">
								<li>排序：<a href="#">发帖时间</a>|<a>回复/查看</a>|<a>查看</a></li>
								<li>时间：<a href="#">全部时间</a>|<a>一天</a>|<a>两天</a>|<a>一周</a>|<a>一个月</a>|<a>三个月</a></li>
							</ul>
						</span> -->
					</div>
					<span style="width: 10%;">作者/最后修改</span>
					<span style="width: 10%;">回复/查看</span>
					<span>最后发表</span>
				</div>
				<c:forEach items="${topicList }" var="t">
					<div class="block">
						<div class="left">
							<span>
								<a href="ps.topic?id=${t.id }">
									<img style="margin-bottom: 4px; margin-right: 10px;" src="static/image/folder_common.gif">${t.title }
								</a>
							</span>
						</div>
						<div class="right">
							<span><a href="user?id=${t.user.id }">${t.user.username }</a></span>
							<span class="date">${t.updatetime }</span>
						</div>
						<div class="right">
							<span>${t.replies }</span>
							<span>${t.clicks }</span>
						</div>
						<div class="right" style="width: 8%;">
							<c:if test="${t.reply != null }">
								<span><a href="user?id=${t.reply.user.id }">${t.reply.user.username }</a></span>
								<span class="date">${t.reply.createtime }</span>
							</c:if>
							<c:if test="${t.reply == null }">
								<span><a href="user?id=${t.user.id }">${t.user.username }</a></span>
								<span class="date">${t.updatetime }</span>
							</c:if>
						</div>
					</div>
				</c:forEach>
			</div>
		</div>
	</div>
</body>
<script type="text/javascript" src="static/js/jquery-3.3.1.js"></script>
<script type="text/javascript" src="static/js/bootstrap.js"></script>
<script type="text/javascript">
	var msg = '${msg}';
	if(msg != "") {
		$('<div>').appendTo('body').addClass('alert alert-info').html(msg).show().delay(1500).fadeOut();
	}
</script>
</html>